package com.future.mayi.activity;

import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;

import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.HttpRequest;
import com.future.baselib.utils.ToastUtils;
import com.future.mayi.R;
import com.future.mayi.utils.HtmlFormat;

import org.json.JSONException;
import org.json.JSONObject;

import butterknife.BindView;

public class InstructionsActivity extends BaseTitleActivity {
    @BindView(R.id.web_view)
    WebView webView;

    public static void startActivity(Context context) {
        context.startActivity(new Intent(context,InstructionsActivity.class));
    }

    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("成色说明");

    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_instructions);
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initDates() {
        new HttpRequest<DefaultResponse>()
                .with(mContext)
                .setApiCode(ApiCst.chengseshuoming)
                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
                    @Override
                    public void onSuccess(DefaultResponse response) {
                        String responseString;
                        try {
                            JSONObject object = new JSONObject(response.content);
                            responseString = object.optString("info");
                            webView.loadDataWithBaseURL(null, HtmlFormat.getNewContent(responseString), "text/html", "utf-8", null);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }

                    @Override
                    public void onFail(String message, DefaultResponse response) {
                        ToastUtils.shortToast(mContext, message);
                    }
                })
                .start(new DefaultResponse());
    }

    @Override
    protected void initListener() {

    }


}
